<?php
session_start();
require_once 'ini.php';
require_once 'authen.php';

require_once "controls/menu_db.php";
 
function headerHTML($screen="",$title=""){
 
if ($screen=="stock"){
	$stock_active="active";
}else if ($screen=="master"){
	$master_active="active";
}else if ($screen=="account"){
	$account_active="active";
}else if ($screen=="service"){
	$service_active="active";
}
else if ($screen=="report"){
	$report_active="active";
}
else if ($screen=="student"){
	$student_active="active";
}
else if ($screen=="employee"){
	$employee_active="active";
}else if ($screen=="main"){
	$main_active="active";
}
$curr = date('d/m/Y');

$m_menu = new M_Menu();
$val = $m_menu->getCurrentYearTerm(); 
 
$user = $m_menu->loadUserProfile($_SESSION['userid']);
 
?>
<!DOCTYPE html>
<html lang="en">
<head>

  <meta charset="utf-8">
<title>School Management</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta name="description" content="">
  <meta name="author" content="">
<style>
	.medatory{
		color:red;
	}
	@media print{@page {size:landscape}}
</style>
	<!-- Styles -->
  	<link href='css/chosen.css' rel='stylesheet' tyle="text/css" media='all'>
	<link href="css/bootstrap.min.css" rel="stylesheet" type="text/css" media='all'>
	<link href="css/bootstrap-select.css" rel="stylesheet" type="text/css" media='all'>
	<link href='css/datepicker.css' rel='stylesheet' tyle="text/css" media='all'>

	<link href="css/avocado.css" rel="stylesheet" type="text/css" id="theme-style" media='all'>
	<link href="css/prism.css" rel="stylesheet/less" type="text/css" media='all'>
 
  	<!--link href='http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,400,600,300' rel='stylesheet' type='text/css'--> 
	<link href="css/css_font.css" rel="stylesheet/less" type="text/css" media='all'>
	<style type="text/css">
		body { padding-top: 102px; }
	</style>
	<link href="css/bootstrap-responsive.css" rel="stylesheet" media='all'>
  
	<!-- JavaScript/jQuery, Pre-DOM -->
	<script src="js/jquery.min.js"></script> 
 
	<script src="js/excanvas.min.js"></script>
	<script src="js/jquery.flot.js"></script>
 
	<script src="js/jquery.cookie.js"></script>
	<script src="js/jquery.blockUI.js"></script>
	<script src="js/myScript/js_profile.js"></script>
	<script src="js/js_print.js"></script>
<script>
		var _cdate="<?php echo $curr;?>";
		function BlockUI(){
			$.blockUI({ css: {
				  border: 'none',
				  padding: '15px',
				  backgroundColor: '#000',
				  '-webkit-border-radius': '10px',
				  '-moz-border-radius': '10px',
				  opacity: .5,
				  color: '#fff'
			  }, message: '<img src="./img/ajax-loader.gif" alt="Wating..." /><br/> Please wait...'
		   });
		 }
</script>
  <!-- HTML5, for IE6-8 support of HTML5 elements -->
  <!--[if lt IE 9]>
    <script src="js/html5.js"></script>
  <![endif]-->

</head>
<body>
<div id="popupConfirm" class="modal hide fade" style="width:350px;top:35% !important;margin-left:-180px;" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

    <div class="modal-header" style='padding-top:20px;padding-bottom:25px;'>
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h3 id="myModalLabel" style="color:#a41a41;"><img src='img/remove.png'/> &nbsp;&nbsp;คุณต้องการลบข้อมูล ?</h3>
    </div>
  
    <div class="modal-footer center" style="text-align:center !important;padding-top:15px;padding-bottom:15px;">
        <button type='submit' class="btn btn-danger" id="btnDelete">ตกลง</button>
        <button class="btn" data-dismiss="modal" aria-hidden="true">ยกเลิก</button>
    </div>
 
</div> 
	<!-- Top Fixed Bar -->
	<div class="navbar navbar-inverse navbar-fixed-top">

		<!-- Top Fixed Bar: Navbar Inner -->
		<div class="navbar-inner">

			<!-- Top Fixed Bar: Container -->
			<div class="container">

				<!-- Mobile Menu Button -->
				<a href="#">
					<button type="button" class="btn btn-navbar mobile-menu">
						<span class="icon-bar"></span>
						<span class="icon-bar"></span>
						<span class="icon-bar"></span>
					</button>
				</a>
				<!-- / Mobile Menu Button -->

				<!-- / Logo / Brand Name -->
				<a class="brand" href="#"><i class="icon-shield"></i> School<b>Management</b></a>
				<!-- / Logo / Brand Name -->

				<!-- User Navigation -->
				<ul class="nav pull-right">
				 

					<!-- User Navigation: User -->
					<li class="dropdown">

						<!-- User Navigation: User Link -->
						<a href="#" class="dropdown-toggle" data-toggle="dropdown">
							<i class="icon-user icon-white"></i> 
							<span class="hidden-phone"><?php echo $_SESSION['login_name'];?></span>
						</a>
						<!-- / User Navigation: User Link -->

						<!-- User Navigation: User Dropdown -->
						<ul class="dropdown-menu">
							<li><a href="#settings" data-toggle='modal' class='userprofile'><i class="icon-user"></i> Profile</a></li>
 							<li class="divider"></li>
							<li><a href="logout.php"><i class="icon-off"></i> Logout</a></li>
						</ul>
						<!-- / User Navigation: User Dropdown -->

					</li>
					<!-- / User Navigation: User -->

				</ul>
				<!-- / User Navigation -->

			</div>
			<!-- / Top Fixed Bar: Container -->

		</div>
		<!-- / Top Fixed Bar: Navbar Inner -->
		
	<!-- Top Fixed Bar: Breadcrumb -->
		<div class="breadcrumb clearfix">

			<!-- Top Fixed Bar: Breadcrumb Container -->
			<div class="container">

				<!-- Top Fixed Bar: Breadcrumb Location -->
				<ul class="pull-left">
					<li><a href="dashboard.php"><i class="icon-home"></i> Home</a> <span class="divider">/</span></li>
							<?php
							 if ($screen =="master"){
							?>
							<li class="active"><a href="#"><i class="icon-desktop"></i> Master</a><span class="divider">/</span> </li>
							<li class="active"> <a href="#"><i class="icon-cog"></i> <?php echo $title; ?></a> </li>
							<?php }else if ($screen == "stock"){?>
							<li><a href="#"><i class="icon-th-large"></i> งานพัสดุ</a> <span class="divider">/</span> </li>
							<li class="active"> <a href="#"><i class="icon-desktop"></i> <?php echo $title; ?></a> </li>
							<?php
							 }else if ($screen=="student"){
							?>
							<li><a href="#"><i class="icon-group"></i> งานนักเรียน</a> <span class="divider">/</span> </li>
							<li class="active"> <a href="#"><i class="icon-desktop"></i> <?php echo $title; ?></a> </li>
							<?php
							 }else if ($screen=="service"){
							?>
							<li><a href="#"><i class="icon-folder-close-alt"></i> งานบริการ</a> <span class="divider">/</span> </li>
							<li class="active"> <a href="#"><i class="icon-desktop"></i> <?php echo $title; ?></a> </li>
							<?php
							 }else if ($screen=="account"){
							?>
							<li><a href="#"><i class="icon-usd"></i> งานบัญชี</a> <span class="divider">/</span> </li>
							<li class="active"> <a href="#"><i class="icon-desktop"></i> <?php echo $title; ?></a> </li>
							<?php
							 }else if ($screen=="employee"){
							?>
							<li><a href="#"><i class="icon-user"></i> งานบุคลากร</a> <span class="divider">/</span> </li>
							<li class="active"> <a href="#"><i class="icon-desktop"></i> <?php echo $title; ?></a> </li>
							<?php
							 }else if ($screen=="report"){
							?>
							<li><a href="#"><i class="icon-bar-chart"></i> รายงาน</a> <span class="divider">/</span> </li>
							<li class="active"> <a href="#"><i class="icon-desktop"></i> <?php echo $title; ?></a> </li>
							<?php
							 }else{
							?>
							<li class="active"><a href="dashboard.php"></li>
							 <?php }?>
					
				</ul>
				<!-- / Top Fixed Bar: Breadcrumb Location -->

				<!-- Top Fixed Bar: Breadcrumb Right Navigation -->
				<ul class="pull-right">
					<li><font style='color:#666;'>ปีการศึกษา : </font><span style='color:red;font-weight:bold;' id='year_term'/><?php echo $val['Year'].'&nbsp;/&nbsp;'.$val['Term'];?></span></li>
					<li>&nbsp;</li>
					<li><a href="logout.php"><i class="icon-off"></i> Logout</a></li>
				</ul>
				<!-- / Top Fixed Bar: Breadcrumb Right Navigation -->

			</div>
			<!-- / Top Fixed Bar: Breadcrumb Container -->

		</div>
		<!-- / Top Fixed Bar: Breadcrumb -->

	</div>
	<!-- / Top Fixed Bar -->

	<!-- Moldule: Settings -->
	<div id="settings" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

	  <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h3 id="myModalLabel"><i class="icon-cog"></i> ข้อมูลผู้ใช้งาน</h3>
        </div>
  <form class="form-horizontal">
        <div class="modal-body">
				<div class="control-group">
						<label class="control-label" for="inputName"><i class="icon-double-angle-right"></i> Username</label>
						<div class="controls">
							 <input type="text" id="username_popup" readonly class='span3' value="<?php echo $user['username']; ?>" required maxlength="100" placeholder="Username">
						</div>
				</div>
				<div class="control-group">
						<label class="control-label" for="inputName"><i class="icon-double-angle-right"></i> Password</label>
						<div class="controls">
							 <input type="password" id="password_popup" class='span3' style='height:30px;background-color:#eef2e4;' maxlength="100" required placeholder="Password">
						</div>
				</div>
				
				<div class="control-group">
						<label class="control-label" for="inputName"><i class="icon-double-angle-right"></i>Confirm Password</label>
						<div class="controls">
							 <input type="password" id="password_confirm_popup" class='span3' style='height:30px;background-color:#eef2e4;' maxlength="100" required placeholder="Confirm Password">
						</div>
				</div>
				
				 <div class="control-group">
						<label class="control-label" for="inputName"><i class="icon-double-angle-right"></i> ชื่อ-นามสกุล</label>
						<div class="controls">
							 <input type="text" id="Name_popup" class='span3' value="<?php echo $user['name']; ?>" required maxlength="100" placeholder="ชื่อ-นามสกุล">
						</div>
				</div>
				
				<div class="control-group">
						<label class="control-label" for="inputName"><i class="icon-double-angle-right"></i>  แผนก/ฝ่าย</label>
						<div class="controls">
							<input type="text"  class='span3' value="<?php echo $user['departmentname']; ?>" readonly maxlength="100" placeholder="แผนก/ฝ่าย">
						</div>
				</div>
				<div class="control-group">
					 <label class="control-label" for="inputName"><i class="icon-double-angle-right"></i> กลุ่มผู้ใช้งาน</label>
						<div class="controls">
							<input type="text"  class='span3' value="<?php echo $user['groupname']; ?>" readonly maxlength="100" placeholder="กลุ่มผู้ใช้งาน">
						</div>
				</div>
				 
        </div>


        <div class="modal-footer">
			<button type='button' class="btn btn-primary" id="btnSaveProfile">บันทึก</button>
			<button class="btn" data-dismiss="modal" aria-hidden="true">ยกเลิก</button>
        </div>
	</form>

	</div> 
	<!-- / Module: Settings -->

	 
	 
		
<!-- Content Container -->
	<div class="container">

		<!-- Main Navigation: Box -->
		<div class="navbar navbar-inverse" id="nav">

			<!-- Main Navigation: Inner -->
			<div class="navbar-inner">

				<!-- Main Navigation: Nav -->
				<ul class="nav">

				 
					<!-- / Main Navigation: Dashboard -->
					<?php 
						$result = $m_menu->getUserAuthen($_SESSION['userid']);
						$student_menu="";
						$employee_menu ="";
						$master_menu="";
						$stock_menu="";
						$service_menu="";
						$account_menu="";
						$report_menu="";
						$report_menu_stock="";
						$report_menu_account="";
						$p=1;
						while($row=$result->FetchRow()){
							if ($row['type']=='ST'){
								$student_menu .="<li><a href='".$row['url']."'><i class='icon-circle'></i>".$row['name']."</a></li>";
							}else if($row['type']=='EP'){
								$employee_menu .="<li><a href='".$row['url']."'><i class='icon-check'></i>".$row['name']."</a></li>";
							}else if ($row['type']=='MA'){
								$master_menu .= "<li><a href='".$row['url']."'><i class='icon-cog'></i>".$row['name']."</a></li>";
							}else if ($row['type']=='SO'){
								$stock_menu .= "<li><a href='".$row['url']."'><i class='icon-edit'></i>".$row['name']."</a></li>";
								if ($_SESSION['permission'][$row['url']]['ap']==1){
								$stock_menu .= "<li><a href='".$row['url'].'?t=ap'."'><i class='icon-edit'></i>อนุมัติ".$row['name']."</a></li>";
								}
							}else if ($row['type']=='SE'){
								$service_menu .= "<li><a href='".$row['url']."'><i class='icon-folder-close-alt'></i>".$row['name']."</a></li>";
							}else if ($row['type']=='AC'){
								$account_menu .= "<li><a href='".$row['url']."'><i class='icon-usd'></i>".$row['name']."</a></li>";
							}else if ($row['type']=='RE'){
								if ($row['url']=='report_stock.php'){
								
									$report_menu_stock .="<li><a href='".$row['url']."?p=".$p."'><i class='icon-file-text-alt'></i>".$row['name']."</a></li>";
									$p++;
									
								}else if ($row['url']=='report_employee_salary.php' || $row['url']=='report_monthly.php' || $row['url']=='report_payment.php' ){
									$report_menu_account.="<li><a href='".$row['url']."'><i class='icon-file-text-alt'></i>".$row['name']."</a></li>";
								}else {
									$report_menu .= "<li><a href='".$row['url']."'><i class='icon-file-text-alt'></i>".$row['name']."</a></li>";
								}
							}
						}
					?>
					<?php if ($student_menu !='') {?>
					<li class="dropdown <?php echo $student_active;?>">
							<a href="#" class="dropdown-toggle" data-toggle="dropdown">
								<i class="icon-group"></i> งานนักเรียน <b class="caret"></b>
							</a>
							 <ul class="dropdown-menu">
								<?php echo $student_menu;?>
							</ul>
					</li>
					<?php } ?>
					
					<?php if ($employee_menu !='') {?>
					<!-- Main Navigation: Employee -->
					<li class="dropdown <?php echo $employee_active;?>">
							<a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="icon-user">
								</i> งานบุคลากร <b class="caret"></b>
							</a>
							<ul class="dropdown-menu">
								<?php echo $employee_menu;?>
							</ul>
					</li>
					<?php }?>
					<!-- / Main Navigation: Employee -->
					<?php if ($service_menu !='') {?>
					<!-- Main Navigation: Service -->
					<li class="dropdown <?php echo $service_active;?>">
							<a href="#" class="dropdown-toggle" data-toggle="dropdown">
								<i class="icon-folder-close-alt"></i> งานบริการ <b class="caret"></b>
							</a>
							<ul class="dropdown-menu">
								 <?php echo $service_menu;?>			
							</ul>
					</li>
					<?php } ?>
					<!-- / Main Navigation: Service -->

					<!-- Main Navigation: Product -->
					 <?php if ($stock_menu!='') {?>
					<li class="dropdown <?php echo $stock_active;?>">
							<a href="#" class="dropdown-toggle" data-toggle="dropdown">
								<i class="icon-th-large"></i> งานพัสดุ <b class="caret"></b>
							</a>
							<ul class="dropdown-menu">
								<?php echo $stock_menu;?>
							</ul>
					</li>
					<?php }?>
					<!-- / Main Navigation: Product -->
					
					 <?php if ($account_menu!='') {?>
				     <!-- Main Navigation: Account -->
					<li class="dropdown <?php echo $account_active;?>">
							<a href="#" class="dropdown-toggle" data-toggle="dropdown">
								<i class="icon-usd"></i> งานบัญชี <b class="caret"></b>
							</a>
							<ul class="dropdown-menu">
								<?php echo $account_menu;?>
							</ul>
					</li>
					<?php } ?>
					<!-- / Main Navigation: Account -->
					<!-- Main Navigation: Report -->
					<?php if ($report_menu !='' || $report_menu_account !='' || $report_menu_stock != ''){ ?>					
					<li class="dropdown <?php echo $report_active;?>">
						<a href="#" class="dropdown-toggle" data-toggle="dropdown">
							<i class="icon-bar-chart"></i> รายงาน <b class="caret"></b>
						</a>
						<ul class="dropdown-menu">
						<?php echo $report_menu;?>
						<?php if ($report_menu_stock!='') { ?>
							<li class="dropdown-submenu">
								<a href="#"><i class="icon-file-alt"></i> รายงานสินค้าและพัสดุ</a>
								<ul class="dropdown-menu">
										<?php echo $report_menu_stock;?>
								</ul>
							</li>							
						<?php } ?>
						 <?php if ($report_menu_account!='') { ?>
							 <li class="dropdown-submenu">
								<a href="report_stock.php"><i class="icon-file-alt"></i> รายงานการจ่ายเงิน</a>
								<ul class="dropdown-menu">
										<?php echo $report_menu_account; ?>
								</ul>
							</li>	
						<?php } ?>
						
						 
						 </ul>
					</li>
					<?php } ?>
					<!-- / Main Navigation: Report -->
   			  <!-- Main Navigation: master -->
					<?php if ($master_menu!=''){ ?>
					<li class="dropdown <?php echo $master_active;?>">
							<a href="#" class="dropdown-toggle" data-toggle="dropdown">
								<i class="icon-desktop"></i> Master <b class="caret"></b>
							</a>
							<ul class="dropdown-menu">
								<?php echo $master_menu;?>
							</ul>
					</li>
					<?php }?>
					<!-- / Main Navigation: master -->
 
				</ul>
				<!-- / Main Navigation: Nav -->
			
			 

			</div>
			<!-- / Main Navigation: Inner -->

		</div>		
<?php
}
function footerHTML(){
	$html = "</div></body>";
	
	echo $html;
}
?>